package 蓝桥._2024.封闭图形个数;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;
// 1:无需package
// 2: 类名必须Main, 不可修改

public class Main {

    static int[] rule = {1,0,0,0,1,0,1,0,2,1};

    static int Compare(int a, int b){
        int aa = a,bb = b;
        int c1 = 0;
        if(a == 0)
            c1 = 1;
        else{
            while(a > 0){
                c1 += rule[a%10];
                a /= 10;
            }
        }
        int c2 = 0;
        if(b == 0)
            c2 = 1;
        else{
            while(b > 0){
                c2 += rule[b%10];
                b /= 10;
            }
        }
        if(c1 != c2)
            return c1 - c2;
        else
            return aa - bb;
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int n = scan.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(scan.nextInt());
        }
        list.sort((a, b) -> Compare(a, b));

        System.out.print(list.get(0));

        for (int i = 1; i < n; i++) {
            System.out.print(" "+list.get(i));
        }

        scan.close();
    }
}